# import pymysql



# # 创建connect
# db=pymysql.connect(
#     host='localhost',
#     port=3308,
#     database='liu',
#     user='root',
#     password='123456',
#     charset='utf8'
# )
# try:
#       cursor = db.cursor()
#       sql = "SELECT * FROM ct_user"
#       cursor.execute(sql)
#       data = cursor.fetchall()
#       print('获取的数据：\n', data, type(data))
#       for item in data:
#           print(item)
# except Exception as e:
#       print("发生异常：", e)
# finally:
#       if 'db' in locals() and db.open:
#           cursor.close()
#           db.close()



# class mysql:
#     def __init__(self,host,database,user,password,port=3308,charset='utf8'):
#         self.host=host
#         self.port=port
#         self.database=database
#         self.user=user
#         self.password=password
#         self.charset=charset
#
#     def insert(self, sql,data):
#         db=pymysql.connect(
#             host=self.host,
#             port=self.port,
#             database=self.database,
#             user=self.user,
#             password=self.password,
#             charset=self.charset
#         )
#         try :
#             with db.cursor() as cursor:
#                 cursor.execute(sql,data)
#                 db.commit()
#                 print('操作成功')
#         except Exception as e:
#             print('操作失败',e)
#         finally:db.close()
#
# if __name__ == '__main__':
#     for i in range(10):
#         sql = "INSERT INTO person VALUES (%s, %s, %s, %s)"
#         name=input('请输入名字')
#         age=int(input('请输入年龄'))
#         sex=input('请输入性别')
#         high=float(input('请输入身高'))
#         data=(name,age,sex,high)
#         db=mysql('localhost','liu','root','123456')
#         db.insert(sql,data)









